/*
 * =====================================================================================
 *
 *       Filename:  cl_socket_addr_factory.cxx
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  05/05/2011 12:20:16 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ken), chen_kenz@emc.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include <cassert>
#include "cl_socket_addr_factory.hxx"
#include "cl_socket_addr_in4.hxx"

namespace neo
{
using namespace std;

CLSocketAddr* CLSocketAddrFactory::create(const string& host, 
                                          int port, 
                                          CLSocketType type) 
{
  if(::getenv("CL_USE_IPV6") != NULL)
  {
    // return new CLSocketAddrIn6(host, port, type);
    return static_cast<CLSocketAddr*>(0);
  }
  else
  {
    return new CLSocketAddrIn4(host, port, type);
  }
}

CLSocketAddr* CLSocketAddrFactory::create(const struct sockaddr* sa) 
{
  assert(sa != NULL);
  CLSocketAddr* peerAddr = NULL;
  switch(sa->sa_family)
  {
    case AF_INET:
      peerAddr = new CLSocketAddrIn4(sa);
      break;
  
    case AF_INET6:
      //peerAddr = new CLSocketAddrIn6(sa);
      break;
  
    default:
      // KENTODO...CLLog
      break;
  }

  return peerAddr;
}

} // neo
